package com.gl.saasservice.sys.controller;

import com.gl.common.vo.ApiData;
import com.gl.framework.web.response.Result;
import com.gl.saasservice.sys.service.UserService;
import com.gl.saasservice.sys.vo.AppUserVO;
import com.gl.saasservice.sys.vo.DepartmentVO;
import com.gl.saasservice.sys.vo.RoleVO;
import com.gl.saasservice.sys.vo.UserDepartmentRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping(path = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户列表
     * @param token
     * @return
     */
    @RequestMapping(value = "/pages", method = RequestMethod.GET)
    @ResponseBody
    public Result pages(@RequestHeader String token,
                        @RequestParam( defaultValue = "0") Integer pageNumber,
                        @RequestParam( defaultValue = "10") Integer pageSize,
                        AppUserVO userVO) {
        return userService.pages(token, pageNumber, pageSize, userVO);
    }

    /**
     * 获取部门
     * @return
     */
    @RequestMapping(value = "/department",method = RequestMethod.GET)
    @ResponseBody
    public Result department(@RequestHeader String token){
        return userService.department(token);
    }

    /**
     * 获取职务
     * @return
     */
    @RequestMapping(value = "/role",method = RequestMethod.GET)
    @ResponseBody
    public Result role(@RequestHeader String token){
        return userService.role(token);
    }

    /**
     * 获取组织架构列表
     * @return
     */
    @RequestMapping(value = "/departmentList/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Result departmentList(@RequestHeader String token,
                                                          @PathVariable Long id){
        return userService.departmentList(token,id);
    }

    /**
     * 授权组织架构权限
     *
     * @param vo
     * @author chensenrong
     */
    @PostMapping(value = "/departmentSave")
    @ResponseBody
    public Result departmentSave(@RequestHeader String token,
                                             @RequestBody UserDepartmentRequestVO vo) {
        return userService.saveUserDepartment(token,vo);
    }

    /**
     * 添加用户信息
     * @param userVO
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public Result add (@RequestHeader String token,
                                   @RequestBody AppUserVO userVO){
        return userService.save(token,userVO);
    }

    /**
     * 更新用户信息
     * @param userVO
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    @ResponseBody
    public Result update (@RequestHeader String token,
                                   @RequestBody AppUserVO userVO){
        return userService.save(token,userVO);
    }


    /**
     * 修改密码
     * @param userVO
     * @return
     */
    @RequestMapping(value = "/changePassword",method = RequestMethod.PUT)
    @ResponseBody
    public Result changePassword (@RequestHeader String token,
                                      @RequestBody AppUserVO userVO){
        return userService.changePassword(token,userVO);
    }


    /**
     * 删除用户信息
     * @return
     */
    @RequestMapping(path = "/{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public Result delete(@RequestHeader String token,
                                     @PathVariable String id){
        return userService.delete(token,id);
    }

    /**
     * 修改状态
     * @param filter
     * @return
     */
    @RequestMapping(path = "/updateStatus",method = RequestMethod.PUT)
    @ResponseBody
    public Result updateStatus (@RequestHeader String token,
                                            @RequestBody AppUserVO filter){
        return userService.UpdateStatus(token,filter);
    }

}
